import time
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from lxml import etree
service = Service("D:\\WPS Cloud Files\\msedgedriver.exe")
opt = Options()
opt.add_argument("--disable-blink-features=AutomationControlled")

browser = webdriver.Edge(service=service,options=opt)
browser.maximize_window()

browser.get('https://nmixx.jype.com/')
# ____________________________________________________________________
# 只有开始这个父页面需要等待吧
locator = (By.XPATH,'//*[@id="header"]/button')
try:
    WebDriverWait(browser,9).until(EC.presence_of_element_located(locator))
except:
    print("I just did it.")
# 固定等待格式。 //*[@id="wrap"]/div[3]/div/div[2]/div/ul/li[1]/a/p[2]/span[1]
#              //*[@id="wrap"]/div[3]/div/div[2]/div/ul/li[2]/a/p[2]/span[1]
button1 = browser.find_element(By.XPATH,'//*[@id="header"]/button')
button1.click()
time.sleep(1.5)

button2 = browser.find_element(By.XPATH,'//*[@id="mySidenav"]/ul[1]/li[5]/a')
button2.click()
time.sleep(1.5)
# 再来一遍 ！！！for 格式化！！！ 不行我就删Pycharm！！！
for i in range(1,11):
    locator = (By.XPATH,f'//*[@id="wrap"]/div[3]/div/div[2]/div/ul/li[{i}]/a/p[2]/span[1]')
    try:
        WebDriverWait(browser,3).until(EC.presence_of_element_located(locator))
        notice = browser.find_element(By.XPATH,
                                      f'//*[@id="wrap"]/div[3]/div/div[2]/div/ul/li[{i}]/a/p[2]/span[1]')
        notice.click()
        time.sleep(1)
        title = browser.find_element(By.XPATH,
                                     '//*[@id="wrap"]/div[3]/div/div[2]/div[1]/p[2]').text
        print(title)
        browser.back()
    except:
        pass

""" 又双叒叕 遇到问题了 얘들!!!!!! """
# for i in range(1,11):
#     for j in [2,3]:
#         try:
#             xp = f'//*[@id="container"]/div/form/div/div[1]/div[2]/dl[{i}]/dt/span[{j}]/span[1]/a'
#             voice = browser.find_element(By.XPATH,xp)
#             voice.click()
#         except:
#             pass

    # 为什么点不了发音按钮？？？？ //*[@id="container"]/div/form/div/div[1]/div[2]/dl[1]/dt/span[3]/span[1]/a
    #                          //*[@id="container"]/div/form/div/div[1]/div[2]/dl[6]/dt/span[2]/span[1]/a
    #                          //*[@id="container"]/div/form/div/div[1]/div[2]/dl[10]/dt/span[3]/span[1]/a
""""""
# text = browser.page_source
# ht = etree.HTML(text)
# yeongeo_deul = ht.xpath('//dd[@class="manyLang6 ml20"]/text()')
# order = ht.xpath('//strong/text()')
# for i in range(len(yeongeo_deul)):
#     print(yeongeo_deul[i].strip("\t\n"))
# print(order)

time.sleep(1111)



















